﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Discipulus
{
	public delegate void ConsoleCommand(string[] args);

	static class ConsoleWindow
	{
		public static Dictionary<string, ConsoleCommand> Commands = new Dictionary<string, ConsoleCommand>();
		
		public static bool RunCommand(string commandName, string[] args)
		{
			if (!Commands.ContainsKey(commandName))
				return false;

			try
			{
				Commands[commandName].Invoke(args);
			}
			catch (Exception e)
			{
				//TODO: Temporary, we'll switch to our own console when it's finished.
				System.Console.WriteLine("Generic error!");
				System.Console.WriteLine(e.ToString());
				return false;
			}

			return true;
		}
		
		public static void Init()
		{
			Commands.Add("test", args =>
			{
				System.Console.WriteLine("Hello world!");
			});
		}
	}
}
